home *** CD-ROM | disk | FTP | other *** search
- /*
- randFileName.rx -- Create a random file name for given file
- Written in ARexx
- © 2001 Carl Svensson
- Version 0.9
- */
-
- /* Check for -- and load -- rexxsupport.library */
- if ~show("L","rexxsupport.library") then
- call addlib('rexxsupport.library',0,-30,0)
-
- /* set up variables */
- randname=""
- count=1
-
- /*
- get command line arguments
- len: string length of the random file name (excluding suffix)
- file: file to replace name for
- suffix: "dot"-extension (for example, in "image.gif", "gif" is the suffix)
- */
- parse arg len file suffix
-
- /* start timer */
- time(r)
-
- /* hande filename length */
- if len < 1 then do
- say "LENGTH must be 1 or greater!"
- exit
- end
- len=len+1
-
- /* check for file */
- if exists(file) then
- renfile=1
- else
- renfile=0
-
- /* handle filename suffix */
- suffix=strip(suffix)
- if ~(suffix="") then do
- dotstr=substr(suffix,1,1)
- if dotstr="." then
- suffix=suffix
- else
- suffix="."suffix
- end
- else do
- suffix=".rnd"
- end
-
- /* set up alphabet array */
- alpha.1='a'
- alpha.2='b'
- alpha.3='c'
- alpha.4='d'
- alpha.5='e'
- alpha.6='f'
- alpha.7='g'
- alpha.8='h'
- alpha.9='i'
- alpha.10='j'
- alpha.11='k'
- alpha.12='l'
- alpha.13='m'
- alpha.14='n'
- alpha.15='o'
- alpha.16='p'
- alpha.17='q'
- alpha.18='r'
- alpha.19='s'
- alpha.20='t'
- alpha.21='u'
- alpha.22='v'
- alpha.23='w'
- alpha.24='x'
- alpha.25='y'
- alpha.26='z'
-
- call newname
-
- /* rename file if the file exists, otherwise print new file name */
- if renfile then do
- rename(file,randname)
- say file" renamed to "randname"!"
- end
- else do
- say "New name: "randname
- end
-
- exit
-
- /* generate random name */
- newname:
- randname=""
- do while count < len
- rseed=right(time(e),2)*time(s)
- rnum=random(1,26,rseed)
- rchar=alpha.rnum
- randname=randname""rchar
- count=count+1
- end
- count=1
- randname=randname""suffix
- if renfile & exists(randname) then
- call newname
- return
-